package ee.android.kinokavad;

import ee.android.kinokavad.R;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class KinoKavad extends TabActivity {
	/** Called when the activity is first created. */

	private TabHost mTabHost;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Resources res = getResources(); // Resource object to get Drawables
		mTabHost = getTabHost();  // The activity TabHost
		TabHost.TabSpec spec;  // Resusable TabSpec for each tab
		Intent intent;  // Reusable Intent for each tab

		// Create an Intent to launch an Activity for the tab (to be reused)
		intent = new Intent().setClass(this, MoviesActivity.class);

		// Initialize a TabSpec for each tab and add it to the TabHost

		intent = new Intent().setClass(this, SessionsActivity.class);
		spec = mTabHost.newTabSpec("seansid").setIndicator("SEANSID")
				.setContent(intent); 
//		mTabHost.addTab(spec); 

		// Do the same for the other tabs
		intent = new Intent().setClass(this, MoviesActivity.class);
		spec = mTabHost.newTabSpec("filmid").setIndicator("FILMID")
				.setContent(intent);
//		mTabHost.addTab(spec);



		intent = new Intent().setClass(this, AboutActivity.class);
		spec = mTabHost.newTabSpec("meist").setIndicator("MEIST")
				.setContent(intent);
//		mTabHost.addTab(spec);
		

		mTabHost.setCurrentTab(0);

		setupTab(new TextView(this), "SEANSID", new Intent(this, SessionsActivity.class));
		setupTab(new TextView(this), "FILMID", new Intent(this, MoviesActivity.class));
		setupTab(new TextView(this), "MEIST", new Intent(this, AboutActivity.class));

	}
	private void setupTab(final View view, final String tag, final Intent intent) {
		View tabview = createTabView(mTabHost.getContext(), tag);
		TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);
		mTabHost.addTab(setContent);
	}

	private static View createTabView(final Context context, final String text) {
		View view = LayoutInflater.from(context).inflate(R.layout.tab_bg, null);
		TextView tv = (TextView) view.findViewById(R.id.tabsText);
		tv.setText(text);
		return view;
	}

}